package com.iu.control;

import com.google.gson.Gson;
import com.iu.bean.UserBean;
import com.iu.dao.UserDao;
import com.iu.uitl.Result;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;

@WebServlet( "/register")
public class RegisterServlet extends javax.servlet.http.HttpServlet {
    UserDao userDao;
    Result result;
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        UserBean userBean=new UserBean();
        userBean.setName(request.getParameter("userName"));
        userBean.setPass(request.getParameter("userPassword"));
        userBean.setTel(request.getParameter("phone"));
        userBean.setQq(request.getParameter("QQ"));
        userBean.setQq(request.getParameter("weChat"));
        userDao=new UserDao();
        result = new Result();
        result.isSuccess=userDao.userRegister(userBean);
        if (result.isSuccess){
            result.msg="恭喜您注册成功";
        }else{
            result.msg="抱歉注册失败";
        }
        Gson gson=new Gson();
        String str=gson.toJson(result);
        response.getWriter().append(str);


    }
}
